<template>
	<div class="stock-out-list">
		<van-nav-bar @click-left="eventClickGoBack" left-arrow class="page-head">
			<van-icon @click="$router.push('/accounting/stock-out-add')" name="add-o" slot="right" class="button-icon" />
			<span @click="$router.push('/accounting/stock-out-add')" slot="right" class="button-text">添加</span>
		</van-nav-bar>
        <order-list-by-delete-no-select v-for="(item, index) in $store.state.shop.carts" :index="index" unit="kg" :title="item.title" :number="item.number" :key="index" class="list-item bottom-ash-line" />
		<van-field v-model="message" rows="2" autosize type="textarea" maxlength="50" placeholder="请输入出库备注(50字以内)" show-word-limit></van-field>
		<div class="submit">
			<van-button type="primary" @click="eventClickSubmitStockOut">提交入库单</van-button>
		</div>
	</div>
</template>

<script>
	import { NavBar, Icon, List, Field, Button, Dialog } from 'vant';
	import OrderListByDeleteNoSelect from '../../components/currency/order-list/order-delete-noSelect.vue';
	export default {
		name: "stock-out-list",
		components: {
			[NavBar.name]: NavBar, [List.name]: List, [Field.name]: Field,
			[Button.name]: Button, [Icon.name]: Icon,
			OrderListByDeleteNoSelect,
		},
		data() {
			return {
				clickAddButton: '',
				message: '',
				stock: {
					loading: false, finished: false,
					page: 0, limit: 30
				}
			}
        },
		methods: {
			buildConfirmOrderDataset() {
				var result = [];
				if (this.$store.state.shop.carts) {
					for (let x of this.$store.state.shop.carts) {
						result.push({
							garbageid: x.idList,
							id: x.id,
							weighting_num: x.number,
                            danweiming: x.unit
						});
					}
				}
				return result;
			},
			eventClickGoBack() {
				this.$router.go(-1);
			},
			eventClickSubmitStockOut() {
				var url = '/api/home/order/shopadd',
					param = {
						is_tracing: 1,
						garbagelist: JSON.stringify(this.buildConfirmOrderDataset()),
                        token: this.$store.state.options.user.token,
                        remark: this.message,
                        type: 'ruku'
                    };
                    
				this.$util.postRequestInterface(url, param, (res) => {
					Dialog.alert({
						title: '提示', message: '已提交'
					}).then(() => {
                        this.$store.commit('shop/resetShopCartsDataset', []);
						this.$router.go(-1);
					});
				});
			}
        }
	}
</script>

<style scoped lang="scss">
	.stock-out-list {
		.page-head {
			background-color: #00cc00;

			.van-icon-arrow-left,
			.van-nav-bar__text,
			.button-icon,
			.button-text {
				color: #ffffff !important;
			}

			.button-icon {
				font-size: 1.6rem;
			}

			.button-text {
				padding-left: 0.8rem;
				position: relative;
				top: 1px;
			}
		}
		.submit {
			width: 100%;
			position: absolute;
			bottom: 0;
			.van-button {
				width: 100%;
			}
			.van-button--primary {
				background-color: #00cc00;
			}
		}
	}
</style>